package xyz.yq56.easytool.utils.excel;

import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import xyz.yq56.easytool.enums.PoiType;
import xyz.yq56.easytool.enums.SystemProperty;
import xyz.yq56.easytool.utils.log.LogUtil;
import xyz.yq56.easytool.utils.system.SystemUtil;

/**
 * 封装POI，实现简单的Excel操作等
 *
 * @author yi qiang
 * @date 2021/9/23 0:39
 */
public class ExcelUtil {

    private ExcelUtil() {
    }

    /**
     * 简单List对象转化为Excel表单
     */
    public static <T> void listToExcel(List<T> list, String path, String fileName) {
        try {
            Workbook wb = new HSSFWorkbook();
            Sheet sheet = wb.createSheet();

            try (OutputStream fileOut = new FileOutputStream(path + SystemUtil.getProperty(SystemProperty.FILE_SEPARATOR)
                    + fileName + PoiType.XLSX.getExtension())) {
                wb.write(fileOut);
            }
        } catch (Exception e) {
            LogUtil.error("ListToExcel Failed", e,null);
        }

    }


}
